<template>
  <div class="page-popup">
    <Form>
      <FormItem label="开关" style="margin-bottom: 0px">
        <Switch v-model="isOpen" @on-change="handleChange"></Switch>
      </FormItem>
      <FormItem label="模板" style="margin-bottom: 0px">
        <a href="./template.xlsx" target="_blank">点击下载</a>
      </FormItem>
    </Form>
  </div>
</template>
<script setup>
import { ref } from 'vue';
const local_key = 'ozon-crawl-switch-status';
let isOpen = ref(localStorage.getItem(local_key) === '1');
function handleChange() {
  if (isOpen.value) {
    localStorage.setItem(local_key, '1');
  } else {
    localStorage.setItem(local_key, '0');
  }
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
    chrome.tabs.sendMessage(
      tabs[0].id,
      {
        action: 'ozonCrawlStatusChange',
        data: isOpen.value,
      },
      function (response) {
        console.log(response.text);
      }
    );
  });
}
</script>
<style lang="less" scoped>
.page-popup {
  padding: 10px;
  min-width: 200px;
}
/deep/ .ivu-form-item-label {
  color: rgba(255, 255, 255, 0.7) !important;
}
</style>
